//
//  values.swift

import Foundation
import UIKit


let iw = UIScreen.main.bounds.size.width
let ih = UIScreen.main.bounds.size.height
var textURL = "www.baidu.com"  //http://www.canseq.com
var isRelease = false


//
//extension String {
//    func has(v:String)->Bool {
//        return (self.components(separatedBy: v).count) > 1
//    }
//}


extension UIWindow {
    // 获取当前活动的控制器
    public var visibleViewController:UIViewController? {
        return UIWindow.getVisibleViewControllerFrom(vc: self.rootViewController)
    }
    
    public static func getVisibleViewControllerFrom(vc:UIViewController?) -> UIViewController? {
        if let nc = vc as? UINavigationController {
            return UIWindow.getVisibleViewControllerFrom(vc: nc.visibleViewController)
        } else if let tc = vc as? UITabBarController {
            return UIWindow.getVisibleViewControllerFrom(vc: tc.selectedViewController)
        } else {
            if let pvc = vc?.presentedViewController {
                return UIWindow.getVisibleViewControllerFrom(vc: pvc)
            } else {
                return vc
            }
        }
    }
}
